package cn.usian.service.Impl;

import cn.usian.dao.EmpMapper;
import cn.usian.pojo.Emp;
import cn.usian.service.EmpService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional
public class EmpServiceImpl implements EmpService {
    @Resource
    private EmpMapper empMapper;


    @Override
    public Page<Emp> findPage(String name, String age, Integer pageNum) {
        LambdaQueryWrapper<Emp> queryWrapper  = new LambdaQueryWrapper<>();
        queryWrapper.like(name!=null,Emp::getName,name);
        queryWrapper.gt(age!=null,Emp::getAge,age);
        return empMapper.selectPage(new Page<>(pageNum,2),queryWrapper);

    }

    @Override
    public void add(Emp emp) {
        empMapper.insert(emp);
    }

    @Override
    public void updelete(int id) {
        Emp emp = new Emp();
        emp.setId(id);
        emp.setDid(id);
        empMapper.deleteById(id);
    }
}
